#!/bin/sh
if [ $# -lt 1 ]; then
	echo "Usage:"
	echo "generate_svg.sh DIR"
	echo "Where DIR is the directory of the SVG 11 test suite"
	exit 0
fi

HARNESSDIR=$1"/harness/svg"
WWWPATH="http://www.w3.org/Graphics/SVG/Test/20110816/svg/"
WWWOUT="http://enesim.googlecode.com/svn/wiki/gallery/svg_test/"
OUTPUT="../../../wiki/EsvgTestSuite.wiki"
OUTPUTDIR="../../../wiki/svg_test/"

if [ ! -e $HARNESSDIR ]; then
	echo "Invalid harness directory"
fi

# the idea is to generate a wiki table with the following columns:
# file name
# the loader succeed | the loader failed | the loader SEGV
# the result image link
# the original svg link
echo "#summary Esvg Test Suite based on the SVG 1.1 2nd Edition Test Suite" > $OUTPUT
echo "#labels Featured" >> $OUTPUT
echo "=Esvg Test Suite=" >> $OUTPUT
echo "|| *File* || *Result* || *Status* ||" >> $OUTPUT
for i in `ls $HARNESSDIR/*.svg`; do
	svg=$i
	png="`basename $i`.png"
	esvg_loader $svg $OUTPUTDIR/$png > /dev/null 2>&1
	err=$?
	if [ $err -eq 136 ]; then
		errstr="SIGFPE"
	elif [ $err -eq 134 ]; then
		errstr="SIGABRT"
	elif [ $err -eq 139 ]; then
		errstr="SIGSEGV"
	elif [ $err -eq 0 ]; then
		errstr="OK"
	else
		errstr="UNKNOWN ($err)"
	fi
	echo "|| [$WWWPATH`basename $svg` `basename $svg`] || [${WWWOUT}${png} $png] || $errstr ||" >> $OUTPUT
done

